﻿using System;
using System.Collections.Generic;
using System.Text;
using BusinessLogicDAL;
using Model.BusinessLogic.FindEntityInfo;
using System.Data;
using MyExection;
using Model.BusinessLogic.EntityInfo;
using System.Data.SqlClient;
using Model.Security.EntityInfo;
using SecurityDAL;
using Model.Security.FindEntityInfo;

namespace BusinessLogicBLL
{
    public class BuMenChanPinRenWuBLL
    {
        BuMenChanPinRenWuDAL buMenChanPinRenWuDAL = null;
        DeptDAL deptDAL = null;
        public BuMenChanPinRenWuBLL()
        {
            buMenChanPinRenWuDAL = new BuMenChanPinRenWuDAL();
            deptDAL = new DeptDAL();
        }
        /// <summary>
        /// 创建人：
        /// 创建时间：2010-7-12
        /// 功能介绍：查询DataTable信息
        /// </summary>
        /// <param name="FindEntity  findEntity"></param>
        /// <returns></returns>
        public DataTable SearchByFindEntity(FindBuMenChanPinRenWuEntity findEntity)
        {
            try
            {
                return buMenChanPinRenWuDAL.SearchByFindEntity(findEntity);
            }
            catch (CustomException)
            {
                throw new CustomException("查询DataTable信息出错，请重试！");
            }
        }

        /// <summary>
        /// 创建人：
        /// 创建时间：2010-7-12
        /// 功能介绍：添加BuMenChanPinRenWuEntity
        /// </summary>
        /// <param name="entityInfo"></param>
        /// <returns></returns>
        public bool Add(List<BuMenChanPinRenWuEntity> entityList,string NianFen,string BuMen)
        {
            bool flag = false;
            using (SqlConnection con = new SqlConnection(DBUtility.DBSQLHelper.defaultConnectionString))
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                SqlTransaction trans = con.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                try
                {
                    buMenChanPinRenWuDAL.DelBMCP_RenWu(NianFen, BuMen);
                    foreach (BuMenChanPinRenWuEntity entity in entityList)
                    {
                        flag = buMenChanPinRenWuDAL.Add(trans, entity);
                        if (!flag)
                        {
                            trans.Rollback();
                            return flag;
                        }
                    }
                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                    return false;
                }
            }
            return flag;
        }

        /// <summary>
        /// 创建人：
        /// 创建时间：2010-7-12
        /// 功能介绍：更新BuMenChanPinRenWuEntity
        /// </summary> 
        /// <param name="entityInfo"></param>
        /// <returns></returns>      
        public bool Update(BuMenChanPinRenWuEntity entityInfo)
        {
            try
            {
                return buMenChanPinRenWuDAL.Update(entityInfo);
            }
            catch (CustomException)
            {
                throw new CustomException("更新BuMenChanPinRenWuEntity出错，请重试！");
            }
        }
        /// <summary>
        /// 创建人：
        /// 创建时间：2010-7-12
        /// 功能介绍：根据“key”查询BuMenChanPinRenWuEntity
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public BuMenChanPinRenWuEntity GetListDetailById(string key)
        {
            try
            {
                return buMenChanPinRenWuDAL.GetListDetailById(key);
            }
            catch (CustomException)
            {
                throw new CustomException("根据“key”查询BuMenChanPinRenWuEntity出错，请重试！");
            }
        }
        /// <summary>
        /// 获取有效部门信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllDeptForYouXiao()
        {
            try
            {
                return buMenChanPinRenWuDAL.GetAllDeptForYouXiao();
            }
            catch (CustomException)
            {
                throw new CustomException("获取有效部门信息出错，请重试！");
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="RY_ID"></param>
        /// <returns></returns>
        public Dept GetDeptEntity(int BM_ID)
        {
            try
            {
                return deptDAL.GetListDetailById(BM_ID);
            }
            catch (CustomException)
            {
                throw new CustomException("获取部门信息出错，请重试！");
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DataTable GetBuMen()
        {
            try
            {
                return deptDAL.GetBuMen();
            }
            catch (CustomException)
            {
                throw new CustomException("获取部门信息出错，请重试！");
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DataTable GetDeptFromProc()
        {
            try
            {
                return deptDAL.GetDeptFromProc();
            }
            catch (CustomException)
            {
                throw new CustomException("获取部门信息出错，请重试！");
            }
        }
        /// <summary>
        /// 获取部门产品信息
        /// </summary>
        /// <param name="BM_ID"></param>
        /// <returns></returns>
        public DataTable GetBuMenChanPinXinXi()
        {
            try
            {
                return buMenChanPinRenWuDAL.GetBuMenChanPinXinXi();
            }
            catch (CustomException)
            {
                throw new CustomException("获取部门产品信息出错，请重试！");
            }
        }


        public DataTable GetBuMenChanPinRenWuByNianFen(string NianFen,string BuMen)
        {
             try
            {
           return buMenChanPinRenWuDAL.GetBuMenChanPinRenWuBY_NianFen(NianFen, BuMen);
       }
       catch (CustomException)
       {
           throw new CustomException("获取部门产品信息任务出错，请重试！");
       }
        }
    }
}
